/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImageSelection.java
 *
 * Created on 14/02/2009, 18:43:00
 */
package edu.upf.grupE.interftest;

import edu.upf.grupE.Controller.PictureController;
import edu.upf.grupE.Entities.Album;
import edu.upf.grupE.Entities.FileDescriptor;
import edu.upf.grupE.Entities.Picture;
import edu.upf.grupE.Entities.Tag;
import edu.upf.grupE.Entities.TextDescription;
import edu.upf.grupE.impl.GUILogic;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import org.jdesktop.swingx.JXCollapsiblePane;

/**
 *
 * @author Oscar
 */
public class ImageSelection extends javax.swing.JPanel {

    JXCollapsiblePane buttons;
    ArrayList[] images;
    DefaultMutableTreeNode first;
    DefaultTreeModel modelo;
    Picture actual;
    Picture demo;
    VideoSelection video;
    EditionButtons but;

    /** Creates new form ImageSelection
     * @param buttons, receives a collapsible pane, to be displayed when the botton edit is clicked
     */
    public ImageSelection(JXCollapsiblePane buttons, VideoSelection video, EditionButtons but) {
        this.but = but;
        this.video = video;

        this.buttons = buttons;
        but.setIS(this);

        initComponents();
        this.changeState(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree_images = new javax.swing.JTree();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        btn_addAlbum = new javax.swing.JButton();
        btn_print = new javax.swing.JButton();
        btn_addPicToAlbum = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btn_edit = new javax.swing.JButton();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        jButton4.setText("jButton4");

        setPreferredSize(new java.awt.Dimension(952, 450));

        jScrollPane1.setPreferredSize(new java.awt.Dimension(74, 472));

        first = new DefaultMutableTreeNode("My Albums");
        modelo= new DefaultTreeModel(first);
        jTree_images.setModel(modelo);
        this.UpdateAlbums();
        /*
        DefaultMutableTreeNode padre = new DefaultMutableTreeNode("Parties");
        DefaultMutableTreeNode tio = new DefaultMutableTreeNode("Cadaques.jpg");

        DefaultMutableTreeNode hijo=new DefaultMutableTreeNode("Holidays");
        DefaultMutableTreeNode hija=new DefaultMutableTreeNode("London.png");
        modelo.insertNodeInto(padre,abuelo,0);
        modelo.insertNodeInto(tio,padre,0);
        modelo.insertNodeInto(hijo, abuelo, 1);

        modelo.insertNodeInto(hija, hijo, 0);*/
        jScrollPane1.setViewportView(jTree_images);
        jTree_images.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                jTree_images.getLastSelectedPathComponent();

                if((node!=null) && (node.isLeaf())){
                    if(!node.isRoot()){
                        int index= node.getParent().getIndex(node);
                        int indmain=first.getIndex(node.getParent());
                        System.out.println(index+"  "+indmain);
                        if((images.length>indmain) && (indmain>=0)){
                            if(images[indmain].size()>index){
                                Picture auxiliar= (Picture)images[indmain].get(index);
                                try{
                                    setIcon(auxiliar);
                                }catch(Exception ez){}
                            }
                            //    jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ima_new_paisaje_001.jpg"))); // NOI18N
                        }
                    }
                }
            }
        });

        btn_addAlbum.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/folder12.png"))); // NOI18N
        btn_addAlbum.setText("Add");
        btn_addAlbum.setBorderPainted(false);
        btn_addAlbum.setContentAreaFilled(false);
        btn_addAlbum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_addAlbumActionPerformed(evt);
            }
        });

        btn_print.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/images.jpg"))); // NOI18N
        btn_print.setText("Print");
        btn_print.setBorderPainted(false);
        btn_print.setContentAreaFilled(false);
        btn_print.setEnabled(false);
        btn_print.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_printActionPerformed(evt);
            }
        });

        btn_addPicToAlbum.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/image-viewer.png"))); // NOI18N
        btn_addPicToAlbum.setText("Add Picture to Album");
        btn_addPicToAlbum.setBorderPainted(false);
        btn_addPicToAlbum.setContentAreaFilled(false);
        btn_addPicToAlbum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_addPicToAlbumActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Leopard Icon (70).png"))); // NOI18N
        jButton3.setText("Delete and Album");
        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addComponent(btn_addAlbum)
                .addGap(44, 44, 44)
                .addComponent(btn_addPicToAlbum)
                .addGap(52, 52, 52)
                .addComponent(jButton3)
                .addGap(41, 41, 41)
                .addComponent(btn_print)
                .addContainerGap(120, Short.MAX_VALUE))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_addAlbum)
                    .addComponent(btn_addPicToAlbum)
                    .addComponent(jButton3)
                    .addComponent(btn_print))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jLabel1.setText("Albums");

        btn_edit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Leopard Icon (123).jpg"))); // NOI18N
        btn_edit.setText("Edit");
        btn_edit.setBorderPainted(false);
        btn_edit.setContentAreaFilled(false);
        btn_edit.setEnabled(false);
        add("South", buttons);
        btn_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_editActionPerformed(evt);
            }
        });
        btn_edit.setAction(buttons.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION));

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 214, Short.MAX_VALUE)
            .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jXPanel2Layout.createSequentialGroup()
                    .addGap(0, 107, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addGap(0, 107, Short.MAX_VALUE)))
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 209, Short.MAX_VALUE)
            .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jXPanel2Layout.createSequentialGroup()
                    .addGap(0, 104, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addGap(0, 105, Short.MAX_VALUE)))
        );

        jLabel2.setText("Name:");

        jLabel4.setText("Author:");

        jLabel5.setText("Description:");

        jLabel6.setText("Keywords:");

        jButton1.setText("Save");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Delete");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setText("Image Details:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 8));
        jLabel9.setForeground(new java.awt.Color(255, 0, 51));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 318, Short.MAX_VALUE)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_edit)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(134, 134, 134))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton1)
                                .addGap(18, 18, 18)
                                .addComponent(jButton2)
                                .addGap(40, 40, 40))))
                    .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(127, 127, 127)
                        .addComponent(jLabel9))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btn_edit)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel8)
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2)))
                    .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btn_edit.setText("Edit");
    }// </editor-fold>//GEN-END:initComponents

    private void btn_addAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_addAlbumActionPerformed
        // TODO add your handling code here:
        AddAlbum album = new AddAlbum(this, video);
        album.setVisible(true);
}//GEN-LAST:event_btn_addAlbumActionPerformed

    private void btn_printActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_printActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_btn_printActionPerformed

    private void btn_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_editActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_btn_editActionPerformed

    private void btn_addPicToAlbumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_addPicToAlbumActionPerformed
        // TODO add your handling code here:
        SelectImage select = new SelectImage(this, video);
        select.setVisible(true);
}//GEN-LAST:event_btn_addPicToAlbumActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.changeState(false);
        this.sintext();
        GUILogic.DeletePicture(actual.getId());
        jLabel3.setIcon(null);
        this.UpdateAlbums();
        video.UpdateAlbums();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (jTextField2.getText().length() == 0) {
            jLabel9.setText("Error: Name Field Required");
        } else {

            if ((jTextField4.getText().length() > 0) & (jTextField4.getText().indexOf(",") == -1)) {
                jLabel9.setText("Error: A Minimum of a comma is required in the description field");
            } else {
                jLabel9.setText("");

                actual.setName(jTextField2.getText());


               
                actual.addAuthor(0,jTextField1.getText());

                TextDescription t = new TextDescription();
                t.setDescription(jTextField3.getText());

                String keys[] = jTextField4.getText().split(",");
                int i=0;
                for (String key : keys) {

                   t.addUserKeywords(i, key);
                   i++;
                }

             

                actual.setTextDescription(t);
                actual = PictureController.getById(PictureController.createOrUpdate(actual));
            }

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        DelAlbum del= new DelAlbum(this, video);
        del.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed
   


    public void setIcon(Picture pic) throws MalformedURLException {
        actual = pic;
        btn_edit.setEnabled(true);
        but.setPath(pic.getFileDescriptor().getPath());
        ImageIcon icon= new ImageIcon(pic.getFileDescriptor().getPath());
        int x= icon.getIconWidth();
        int y= icon.getIconHeight();
        Dimension fram=getSize();

        float a1= (float) 197;
        float x2= a1/x;
        float y2= (float)304/y;
        float z= Math.min(x2,y2);
      

        ImageIcon reduced= scale(icon.getImage(), z);
        jLabel3.setIcon(reduced);
        this.sintext();
          this.changeState(true);
        this.showDetails(actual);

    }

    public void setIcon(Icon im) {
        //actual = pic;
        btn_edit.setEnabled(true);

        // but.setPath(pic.getFileDescriptor().getPath());
       
        jLabel3.setIcon(im);

    }

    public void UpdateAlbums() {
        first = new DefaultMutableTreeNode("My Albums");


        ImageIcon folderIcon = new javax.swing.ImageIcon(getClass().getResource("/img/folder_mini.png"));
        ImageIcon leafIcon = new javax.swing.ImageIcon(getClass().getResource("/img/image_icon.png"));



        modelo = new DefaultTreeModel(first);
        Vector<Album> albums = GUILogic.getListAlbums();
        images = new ArrayList[albums.size()];
        System.out.println(albums.size());
        for (int i = 0; i < albums.size(); i++) {


            DefaultMutableTreeNode t = new DefaultMutableTreeNode(albums.get(i).getName());
            JTree tree = new JTree(t);
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();




            modelo.insertNodeInto(t, first, i);

            images[i] = new ArrayList();
            Vector<Picture> pictures = GUILogic.getPicturesByAlbum(albums.get(i).getId());
            if (pictures.size() == 0) {
                //renderer.setIcon(folderIcon);
                renderer.setLeafIcon(leafIcon);
            }
            for (int j = 0; j < pictures.size(); j++) {
                images[i].add(pictures.get(j));
                modelo.insertNodeInto(new DefaultMutableTreeNode(pictures.get(j).getName()), t, j);
            }
            tree.setCellRenderer(renderer);
        }
        System.out.println(modelo);
        jTree_images.setModel(modelo);

    }


    public ImageIcon scale(Image src, double scale) {





        int w = (int)(scale*src.getWidth(this));
        int h = (int)(scale*src.getHeight(this));
        int type = BufferedImage.TYPE_INT_RGB;
        BufferedImage dst = new BufferedImage(w, h, type);
        Graphics2D g2 = dst.createGraphics();
        g2.drawImage(src, 0, 0, w, h, this);
        g2.dispose();

        return new ImageIcon(dst);
    }

public void changeState(boolean x){
    jButton1.setEnabled(x);
    jButton2.setEnabled(x);
    jTextField1.setEnabled(x);
    jTextField2.setEnabled(x);
    jTextField3.setEnabled(x);
    jTextField4.setEnabled(x);



}

public void showDetails(Picture pic){
   this.changeState(true);
   String[] author=pic.getAuthor();
   String name= pic.getName();
   String description= pic.getTextDescription().getDescription();
   String[] keywords= pic.getTextDescription().getUserKeywords();
   if(author[0]==null){
       jTextField1.setText("");
   }else{
       jTextField1.setText(author[0]);
   }
      if(name==null){
       jTextField2.setText("");
   }else{
       jTextField2.setText(name);
   }
      if(description==null){
       jTextField3.setText("");
   }else{
       jTextField3.setText(description);
   }
      if(keywords==null){
       jTextField4.setText("");
   }else{
       String key="";
      
       for(int i=0; i< keywords.length; i++){
            if(!keywords[i].equals("")){
       key=key+keywords[i]+", ";}
       }
       jTextField4.setText(key);
   }
}

public void sintext(){
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
    jTextField4.setText("");
    

}




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_addAlbum;
    private javax.swing.JButton btn_addPicToAlbum;
    private javax.swing.JButton btn_edit;
    private javax.swing.JButton btn_print;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTree jTree_images;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    // End of variables declaration//GEN-END:variables
}
